import {Dimensions, Platform, PixelRatio, StatusBar, NativeModules} from 'react-native';
const { StatusBarManager} = NativeModules
/**
 * 屏幕工具类
 * ui设计基准,iphone 6
 * width:750
 * height:1334
 */

/*
 设备的像素密度，例如：
 PixelRatio.get() === 1          mdpi Android 设备 (160 dpi)
 PixelRatio.get() === 1.5        hdpi Android 设备 (240 dpi)
 PixelRatio.get() === 2          iPhone 4, 4S,iPhone 5, 5c, 5s,iPhone 6,xhdpi Android 设备 (320 dpi)
 PixelRatio.get() === 3          iPhone 6 plus , xxhdpi Android 设备 (480 dpi)
 PixelRatio.get() === 3.5        Nexus 6
 */



const w = Dimensions.get('window').width
const h = Dimensions.get('window').height



let fontScale = PixelRatio.getFontScale();
let pixelRatio = PixelRatio.get();      //当前设备的像素密度


//px转换成dp,pt
const designW = 750 //设计稿的宽度
const w2 = designW / pixelRatio; //设计稿的宽度转换为pt后的宽度
const scale =  w / w2;   //获取缩放比例

/**
 * 设置text为sp
 * @param size sp
 * return number dp
 */
//文字一般是像素/2
const defaultPixel = 2;
const  setSpText = (size) => {
    // size = size / defaultPixel
    // size = Math.round((size * scale + 0.5) * pixelRatio / fontScale);
    size = Math.round(  (size *  scale + 0.5) / pixelRatio )
    return size / defaultPixel;
}

//size传入像素px  返回手机上使用的pt 或者dp
const  scaleSize = (size) => {
    //round函数  返回+0.5后 向下取整
    size = Math.round(size * scale + 0.5);
    return size / pixelRatio;
}
//获取适配尺寸
const getScaleSize = (size) => {

    return  w  * size / designW * scale  ;
}





export default {
    width: w,
    height: h,
    onePixel: 1 / PixelRatio.get(),
    statusBarHeight: Platform.OS === 'ios' ? 20 : StatusBar.currentHeight,
    headerHeight:44,
    setSpText,
    scaleSize,
    getScaleSize,
    //常用像素
    PIXEL_4 : scaleSize(4),
    PIXEL_5 : scaleSize(5),
    PIXEL_8 : scaleSize(8),
    PIXEL_10 : scaleSize(10),
    PIXEL_15 : scaleSize(15),
    PIXEL_16 : scaleSize(16),
    PIXEL_18 : scaleSize(18),
    PIXEL_20 : scaleSize(20),
    PIXEL_24 : scaleSize(24),
    PIXEL_28 : scaleSize(28),
    PIXEL_25 : scaleSize(25),
    PIXEL_30 : scaleSize(30),
    PIXEL_40 : scaleSize(40),
    PIXEL_50 : scaleSize(50),
    PIXEL_60 : scaleSize(60),
    PIXEL_64 : scaleSize(64),
    PIXEL_72 : scaleSize(72),
    PIXEL_75 : scaleSize(75),
    PIXEL_90 : scaleSize(90),
    PIXEL_96 : scaleSize(96),
    PIXEL_80 : scaleSize(80),
    PIXEL_88 : scaleSize(88),
    PIXEL_500 : scaleSize(500),
    PIXEL_545 : scaleSize(545),
    PIXEL_160 : scaleSize(160),
    PIXEL_164 : scaleSize(164),
    PIXEL_170 : scaleSize(170),
    PIXEL_70 : scaleSize(70),
    PIXEL_100 : scaleSize(100),
    PIXEL_110 : scaleSize(110),
    PIXEL_120 : scaleSize(120),
    PIXEL_130 : scaleSize(130),
    PIXEL_140 : scaleSize(140),
    PIXEL_150 : scaleSize(150),
    PIXEL_180 : scaleSize(180),
    PIXEL_230 : scaleSize(230),
    PIXEL_240 : scaleSize(240),
    PIXEL_200 : scaleSize(200),
    PIXEL_220 : scaleSize(220),
    PIXEL_250 : scaleSize(250),
    PIXEL_270 : scaleSize(270),
    PIXEL_280 : scaleSize(280),
    PIXEL_290 : scaleSize(290),
    PIXEL_300 : scaleSize(300),
    PIXEL_320 : scaleSize(320),
    PIXEL_360 : scaleSize(360),
    PIXEL_350 : scaleSize(350),
    PIXEL_448 : scaleSize(448),
    PIXEL_400 : scaleSize(400),
    PIXEL_686 : scaleSize(686),
    PIXEL_700 : scaleSize(700),




}
